<template>
  <div class="page_space">
    <van-loading v-if="loading" class="text-center mt-15"
      >加载中...</van-loading
    >
    <template v-else>
      <p class="title_1">样品信息</p>
      <card-wrap class="mb-15">
        <card-item title="关联采样单号">{{ info.reportCode }}</card-item>
        <card-item title="样品自编号">{{
          info.billInfoDTO &&
          info.billInfoDTO.detailInfoDTOS.businessVarietyCode
        }}</card-item>
        <card-item title="样品名称">{{ info.sampleName }}</card-item>
        <card-item title="采样日期">{{
          info.billInfoDTO && info.billInfoDTO.billDate
        }}</card-item>
        <card-item title="经营主体">{{
          info.billInfoDTO && info.billInfoDTO.intercourseEnterpriseName
        }}</card-item>
        <card-item title="主体类型">{{
          info.intercourseEnterpriseDTO &&
          info.intercourseEnterpriseDTO.subjectTypeText
        }}</card-item>
        <card-item title="所属市场">{{
          info.billInfoDTO && info.billInfoDTO.managementEntName
        }}</card-item>
      </card-wrap>
      <p class="title_1">基本信息</p>
      <card-wrap class="mb-15">
        <card-item title="检测结果">{{ info.resultText }}</card-item>
        <card-item title="检测编号">{{ info.code }}</card-item>
        <card-item title="检测日期">{{ info.reportDate }}</card-item>
        <card-item title="检测类别">{{
          info.billInfoDTO && info.billInfoDTO.uploadBizTypeText
        }}</card-item>
        <card-item title="检测单位">{{
          info.employeeInfoDTO && info.employeeInfoDTO.departmentName
        }}</card-item>
        <card-item title="检测人">{{
          info.employeeInfoDTO && info.employeeInfoDTO.name
        }}</card-item>
        <card-item title="检测人签名">{{
          info.businessFileDTOList && info.businessFileDTOList.fileId
        }}</card-item>
        {{ info.businessFileDTOList.fileId }}
      </card-wrap>
      <p class="title_1">检测信息</p>
      <card-wrap
        v-for="(item, index) in info.reportDetailInfoDTOList"
        :key="index"
        class="mb-15"
        title="检测项目名称"
      >
        <card-item title="检测方法">{{
          item.sampleProjectInfoDTO.methodText
        }}</card-item>
        <card-item title="检测低限">{{
          item.sampleProjectInfoDTO.standardValue
        }}</card-item>
        <card-item title="检出值">{{ item.value }}</card-item>
        <card-item title="快检产品">{{ item.businessVarietyName }}</card-item>
        <card-item title="设备信息">{{ item.equipmentInfoDTO.name }}</card-item>
        <card-item title="结果判定">{{ item.singleResultText }}</card-item>
      </card-wrap>
    </template>
    <div v-if="info.state === 'NORMAL'" class="btn_wrap">
      <button class="btn danger" @click="deleteInspection">作废</button>
    </div>
  </div>
</template>

<script>
import cardWrap from '@/components/base-card/wrap'
import cardItem from '@/components/base-card/item'
import { getInspectionDetail, deleteInspection } from '@/api/inspection'
import { ImagePreview } from 'vant'
export default {
  name: 'inspectionDetails',
  components: { cardWrap, cardItem },
  data() {
    return {
      isComplete: false,
      info: {},
      loading: false,
      id: ''
    }
  },
  created() {
    this.id = this.$route.query.id
    // this.id = '2310161008298270000'
    this.getDetail()
  },
  methods: {
    // 作废
    deleteInspection() {
      this.$dialog
        .alert({
          title: '是否作废?',
          showCancelButton: true
        })
        .then(async () => {
          const { code } = await deleteInspection(this.id)
          if (code === '0') {
            console.log('success')
            this.$router.go(-1)
          } else {
            console.log('fail')
          }
        })
        .catch(() => {
          // on cancel
        })
    },
    async getDetail() {
      const { code, data } = await getInspectionDetail(this.id)
      if (code === '0') {
        console.log(data)
        this.info = data
        this.loading = false
      }
    },
    toComplete() {
      this.isComplete = !this.isComplete
    },
    // 预览
    previewImg(url) {
      ImagePreview({
        images: [url],
        showIndex: false
      })
    }
  }
}
</script>

<style scoped lang="scss">
.avatar {
  width: 68px;
  height: 68px;
  border-radius: 4px;
  margin-right: 6px;

  &:last-child {
    margin-right: 0;
  }
}

.over_line {
  font-size: 14px;
  font-weight: normal;
  line-height: 19px;
  letter-spacing: 0px;
  color: #171819;
  position: relative;
  white-space: normal;

  .show {
    position: absolute;
    bottom: 0;
    right: 0;
    font-family: PingFang SC Medium;
    font-size: 14px;
    font-weight: normal;
    line-height: 19px;
    letter-spacing: 0px;
    /* 蓝 */
    color: #2163e0;
  }
}
</style>
